#ifndef EXPENSE_STRUCT_HH
#define EXPENSE_STRUCT_HH 1


#include <string>
#include <iostream>
#include <vector>
#include "otl8.hpp"

#include <boost/date_time/posix_time/posix_time.hpp>
using namespace boost::posix_time;
using namespace boost::gregorian;


static const char*  expense_struct_s = "SELECT ID, DAY, AMOUNT, ALLOWANCE_ID, CHILD_ALLOWANCE_ID, ACTIVITY_ID, DESCR FROM EXPENSE_STRUCT";

static const char*  expense_struct_i = "INSERT INTO EXPENSE_STRUCT ( ID, DAY, AMOUNT, ALLOWANCE_ID, CHILD_ALLOWANCE_ID, ACTIVITY_ID, DESCR )VALUES(:f1<int>, :f2<date>, :f3<float>, :f4<int>, :f5<int>, :f6<int>, :f7<char[128]>)";

static const char* expense_struct_c = "CREATE TABLE EXPENSE_STRUCT ( ID INTEGER , DAY  , AMOUNT FLOAT , ALLOWANCE_ID INTEGER , CHILD_ALLOWANCE_ID INTEGER , ACTIVITY_ID INTEGER , DESCR VARCHAR(128) )";
class expense_struct
{



public:
expense_struct():_id(0), _day(not_a_date_time), _amount(0), _allowance_id(0), _child_allowance_id(0), _activity_id(0), _descr(""){_select=expense_struct_s;_insert=expense_struct_i;_create=expense_struct_c;}


expense_struct(int a__id, date a__day, float a__amount, int a__allowance_id, int a__child_allowance_id, int a__activity_id, std::string a__descr):_id(a__id) , _day(a__day) , _amount(a__amount) , _allowance_id(a__allowance_id) , _child_allowance_id(a__child_allowance_id) , _activity_id(a__activity_id) , _descr(a__descr) {_select=expense_struct_s;_insert=expense_struct_i;_create=expense_struct_c;}


int id(){return  _id;}
void set_id(int a__id){ _id = a__id;}


date day(){return  _day;}
void set_day(date a__day){ _day = a__day;}


float amount(){return  _amount;}
void set_amount(float a__amount){ _amount = a__amount;}


int allowance_id(){return  _allowance_id;}
void set_allowance_id(int a__allowance_id){ _allowance_id = a__allowance_id;}


int child_allowance_id(){return  _child_allowance_id;}
void set_child_allowance_id(int a__child_allowance_id){ _child_allowance_id = a__child_allowance_id;}


int activity_id(){return  _activity_id;}
void set_activity_id(int a__activity_id){ _activity_id = a__activity_id;}


std::string descr(){return  _descr;}
void set_descr(std::string a__descr){ _descr = a__descr;}


expense_struct & operator=( const expense_struct & x)
{
	_id =  x._id;
	_day =  x._day;
	_amount =  x._amount;
	_allowance_id =  x._allowance_id;
	_child_allowance_id =  x._child_allowance_id;
	_activity_id =  x._activity_id;
	_descr =  x._descr;
	return *this;
}


bool operator==( const expense_struct & x)
{
	return 	_id ==  x._id &&
	_day ==  x._day &&
	_amount ==  x._amount &&
	_allowance_id ==  x._allowance_id &&
	_child_allowance_id ==  x._child_allowance_id &&
	_activity_id ==  x._activity_id &&
	_descr ==  x._descr;
}


friend std::istream& operator >> (std::istream& ist, expense_struct & t)
{
	if (!(ist >> t._id)) return ist;
	if (!(ist >> t._day)) return ist;
	if (!(ist >> t._amount)) return ist;
	if (!(ist >> t._allowance_id)) return ist;
	if (!(ist >> t._child_allowance_id)) return ist;
	if (!(ist >> t._activity_id)) return ist;
	if (!(ist >> t._descr)) return ist;

	return ist;
}

friend std::ostream& operator << (std::ostream& ost, expense_struct & t)
{
	ost << t._id << " ";
	ost << t._day << " ";
	ost << t._amount << " ";
	ost << t._allowance_id << " ";
	ost << t._child_allowance_id << " ";
	ost << t._activity_id << " ";
	ost << t._descr << " ";

	return ost;
}

/*
friend otl_stream& operator >> (otl_stream& ist, expense_struct & t)
{
	ist >> t._id;
	ist >> t._day;
	ist >> t._amount;
	ist >> t._allowance_id;
	ist >> t._child_allowance_id;
	ist >> t._activity_id;
	ist >> t.buf; t._descr=(const char*)t.buf;

	return ist;
}

friend otl_stream& operator << (otl_stream& ost, expense_struct & t)
{
	ost << t._id ;
	ost << t._day ;
	ost << t._amount ;
	ost << t._allowance_id ;
	ost << t._child_allowance_id ;
	ost << t._activity_id ;
	ost << t._descr.c_str() ;

	return ost;
}
*/
std::string select_stmt() { return _select; }
std::string insert_stmt() { return _insert; }
std::string create_stmt() { return _create; }


private:

	int	_id;
	date	_day;
	float	_amount;
	int	_allowance_id;
	int	_child_allowance_id;
	int	_activity_id;
	std::string	_descr;
	std::string _create;
	std::string _select;
	std::string _insert;
char buf[128];
};
#endif
